<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>W3Cschool教程(w3cschool.cn)</title>
</head>
<body>
<h1>获取服务端更新数据</h1>
<div id="result">三生三世</div>

<script>
    if(typeof(EventSource)!=="undefined")
    {
        var source=new EventSource("/SSEDemoServlet");
        source.onopen=function (){
            console.log("source.onopen");
        }
        source.onmessage=function(event)
        {
            document.getElementById("result").innerHTML+=event.data + "<br>";
        };
    }
    else
    {
        document.getElementById("result").innerHTML="抱歉，你的浏览器不支持 server-sent 事件...";
    }
</script>

</body>
</html>